<?php

namespace app\api\controller;

use addons\epay\library\Service;
use app\admin\model\goods\Order;
use app\common\controller\Api;
use app\common\controller\Payment;
use think\Controller;
use think\Db;
use think\Request;


class Fishinggroundfeedback extends Api
{
    private static $model;
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';


    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        self::$model = new \app\common\model\FishingGroundFeedback();
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function lists()
    {
        $pageSize = input('pagesize', 15);

        $groundId = input('ground_id');

        $userId = $this->auth->id;
        $where = [
            'status' => 1,
            'user_id' => $userId
        ];

        if ($groundId) {
            $where['ground_id'] = $groundId;
        }

        $list = self::$model->where($where)->order('createtime desc')->paginate($pageSize);
        if ($list) {
            if ($groundId) {
                $feedback_types = config('site.feedback_types');
            } else {
                $feedback_types = config('site.user_feedback_types');
            }

            foreach ($list as $val) {
                $avatar = \app\common\model\User::where('id', $val->user_id)->value('avatar');
                $val->avatar = get_full_img($avatar);
                $val->type_name = $feedback_types[$val->type];
            }
        }

        $this->success('反馈记录', $list);
    }

    /**
     * 钓场反馈
     */
    public function create()
    {
        $groundId = input('ground_id');

        if ($groundId) {
            $groundInfo = \app\common\model\FishingGround::find($groundId);
            if (!$groundInfo) {
                $this->error('该钓场不存在！');
            }

            if ($groundInfo->source_type != 2) {
                $this->error('该钓场非野钓场！');
            }
        }

        $content = input('content');
        if (!$content) {
            $this->error('请输入反馈内容！');
        }

        $type = input('type');
        $mobile = input('mobile');

        $userId = $this->auth->id;
        $fdata = [
            'user_id' => $userId,
            'content' => $content,
            'ground_id' => $groundId,
            'type' => $type,
            'mobile' => $mobile,
        ];

        $ret = self::$model->create($fdata);
        if (!$ret) {
            $this->error('反馈失败！');
        }

        $this->success('反馈成功！');
    }
}
